﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;

namespace SportStore.Models.Entities
{
    public class User
    {
        private List<Role> _roles;
        private List<Product> _products;
        
        public int UserID { get; set; }

        [Required]
        public string Name { get; set; }

        [Required]
        public string Description { get; set; }

        [Required]
        public List<Role> Roles { 
            get 
            { 
                return _roles ?? (_roles = new List<Role>()); 
            } 
            set 
            { 
                _roles = value; 
            } 
        }

        [Required]
        public List<Product> Products {
            get
            {
                return _products??(_products=new List<Product>());
            }
            set
            {
                _products = value;
            }
        }

        public bool isOwner(int productId)
        {
            Func<int,bool> idLookup = id=>(from p in this.Products where p.ProductID==id select p).Count()>0;
            return idLookup(productId);
        }
    }
}